package Handling;
import java.util.Properties;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Email {

	public Email() {
		
	}
	
	    public void sendEmail(int playerid, int gameid) throws Exception
	    {
	    	System.out.println("los gehts");
	        String host="smtp.gmail.com";
	        int port=587;
	        final String user="stuttgartmonopolymail@gmail.com";
	        final String pass="Stuttgart-Monopoly";
	        
	        GameAdmin game = new GameAdmin();
	        
	        
	        Properties props=new Properties();
	        props.put("mail.smtp.auth", "true");
	        props.put("mail.smtp.starttls.enable", "true");
	        props.put("mail.smtp.host", "smtp.gmail.com");
	        props.put("mail.smtp.port", "587");
	        
	        Session session=Session.getInstance(props, new javax.mail.Authenticator(){
	        	protected PasswordAuthentication getPasswordAuthentication(){
	        		return new PasswordAuthentication(user, pass);
	        	}
	        });
	        System.out.println("hier auch noch");
	        Message message=new MimeMessage(session);
	        
	        message.setFrom(new InternetAddress(user));
	        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(game.getEmail(playerid)));
	        message.setSubject("Du bist dran! Spiele jetzt Stuttgart Monopoly");
	        System.out.println("hier nicht mehr");
	        
	        message.setText("Hi " + game.getNickname(playerid) + ", \n"
	        		+ " Du bist am Zug! Spiele jetzt dein Monopoly Spiel weiter. Klicke einfach auf folgenden Link: \n"
	        		+ " http://localhost:8080/StuttgartMonopoly/Spielfeld.jsp?gameid=" + gameid);
	        System.out.println("auch hier noch");
	        Transport.send(message);
	        System.out.println("SEND");

	    }

}
